<template>
  <div>
    <ul class="todo-main">
      <!--<TodoItem :task="item"/>-->
        <li @mouseenter="activeId=item.id" @mouseleave="activeId=-1" v-for="item in taskList" :key="item.id">
          <label>
            <input @change="upTaskListById(item.id)" :checked="item.isChecked" type="checkbox"/>
            <span>{{item.title}}</span>
          </label>
          <button @click="delTaskListById(item.id)" v-show="item.id === activeId" class="btn btn-danger">删除</button>
        </li>
    </ul>
  </div>
</template>

<script>
import TodoItem from "@/components/TodoItem";
import {mapMutations,mapState,mapActions} from "vuex";

export default {
  name: "TodoMain",
  data() {
    return {
      activeId: -1
    }
  },
  computed:{
    ...mapState(["taskList"])
  },
  methods: {
    ...mapMutations({
      upTaskListById: "UP_TASK_LIST_BY_ID",
      delTaskListById: "DEL_TASK_LIST_BY_ID"
    }),
    ...mapActions(["getTaskList"])
  },
  mounted() {
    this.getTaskList();
  },
  components: {TodoItem}
}
</script>

<style scoped>
/*main*/
.todo-main {
  margin-left: 0;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding: 0;
}

.todo-empty {
  height: 40px;
  line-height: 40px;
  border: 1px solid #ddd;
  border-radius: 2px;
  padding-left: 5px;
  margin-top: 10px;
}
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: block;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

li .done {
  color: #666;
  text-decoration: line-through;
}
</style>